package com.h2cloud.workflow;

import java.util.*;

/**
 * @Package: array
 * @ClassName: test
 * @Author: h2cloud
 * @CreateTime: 2023/1/10 11:01 下午
 * @Description:
 */
public class test {
    public static void main(String[] args) {
        List<Integer> bids = new ArrayList<>();
        bids.add(11);
        bids.add(12);
        bids.add(13);
        bids.add(14);
        bids.add(15);

        Map<Integer, List<String>> bid2Notifiers = new HashMap<>();
        List<String> noticeUser11 = new ArrayList<>(Arrays.asList("1", "2", "3", "4", "10"));
        List<String> noticeUser12 = new ArrayList<>(Arrays.asList("1", "6", "3", "4", "5"));
        List<String> noticeUser13 = new ArrayList<>(Arrays.asList("1", "2", "7", "4", "5"));
        List<String> noticeUser14 = new ArrayList<>(Arrays.asList("1", "2", "3", "8", "5"));
        List<String> noticeUser15 = new ArrayList<>(Arrays.asList("1", "2", "3", "4", "9"));
        bid2Notifiers.put(11, noticeUser11);
        bid2Notifiers.put(12, noticeUser12);
        bid2Notifiers.put(13, noticeUser13);
        bid2Notifiers.put(14, noticeUser14);
        bid2Notifiers.put(15, noticeUser15);

        // 模版，是否合并
        Map<String, Boolean> mergerNotify = new HashMap<>();
        mergerNotify.put("11T", true);
        mergerNotify.put("12T", false);
        mergerNotify.put("13T", true);
        mergerNotify.put("14T", false);
        mergerNotify.put("15T", true);


        List<String> templateIndexInfoList11 = new ArrayList<>(Arrays.asList("11T", "12T", "13T"));
        List<String> templateIndexInfoList12 = new ArrayList<>(Arrays.asList("11T", "14T", "13T"));
        List<String> templateIndexInfoList13 = new ArrayList<>(Arrays.asList("11T", "12T", "15T"));
        List<String> templateIndexInfoList14 = new ArrayList<>(Arrays.asList("11T", "14T"));
        List<String> templateIndexInfoList15 = new ArrayList<>(Arrays.asList("12T", "15T"));
        Map<Integer, List<String>> bid2TemplateIndexList = new HashMap<>();
        bid2TemplateIndexList.put(11, templateIndexInfoList11);
        bid2TemplateIndexList.put(12, templateIndexInfoList12);
        bid2TemplateIndexList.put(13, templateIndexInfoList13);
        bid2TemplateIndexList.put(14, templateIndexInfoList14);
        bid2TemplateIndexList.put(15, templateIndexInfoList15);

        // key：模版id-收件人人oa  value：业务对象列表（合并）
        Map<String, List<Integer>> templateIdAndNotifier2Bids = new HashMap<>();
        // key：模版id-业务对象  value：收件人人oa列表（不合并）
        Map<String, List<String>> templateIdAndBid2Notifiers = new HashMap<>();

        for (Integer bid : bids) {
            List<String> templateIdList = bid2TemplateIndexList.get(bid);
            for (String templateId : templateIdList) {
                for (String noticeUserOa : bid2Notifiers.get(bid)) {
                    // 合并通知
                    if (mergerNotify.get(templateId)) {
                        String key = templateId + "-" + noticeUserOa;
                        templateIdAndNotifier2Bids.putIfAbsent(key, new ArrayList<>());
                        templateIdAndNotifier2Bids.get(key).add(bid);

                    } else {
                        String key = templateId + "-" + bid;
                        templateIdAndBid2Notifiers.putIfAbsent(key, new ArrayList<>());
                        templateIdAndBid2Notifiers.get(key).add(noticeUserOa);
                    }
                }
            }
        }
        System.out.println("templateIdAndNotifier2Bids = " + templateIdAndNotifier2Bids);
        System.out.println("templateIdAndBid2Notifiers = " + templateIdAndBid2Notifiers);
    }
}
